package edu.nf.project.mappers.employeeAndCustomerInformation.convention;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.nf.project.entitys.dto.employeeAndCustomerInformation.CouponDTO;
import edu.nf.project.entitys.entity.employeeAndCustomerInformation.convention.Coupon;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * 优惠券 Mapper 接口
 */
@Mapper
public interface CouponMapper extends BaseMapper<Coupon> {

    // 根据u_id查看信息
    @Select("select ci.customer_id customerId,u.u_id uId,member_id memberId," +
            "c.coupon_id couponId,coupon_name couponName,coupon_type couponType," +
            "discount,min_amount minAmount,reduce_amount reduceAmount,term," +
            "need_point needPoint,coupon_status couponStatus,coupon_describe couponDescribe," +
            "obtain_time obtainTime,deadline_time deadlineTime " +
            "from customer_info_coupon cic " +
            "join customer_info ci on cic.customer_id=ci.customer_id " +
            "join coupon c on cic.coupon_id = c.coupon_id " +
            "join users u on u.u_id = ci.u_id where ci.u_id=#{uId} ")
    List<CouponDTO> listCouponByUsersId(@Param("uId") Integer uId);


    //用户添加优惠卷
    @Insert("INSERT INTO customer_info_coupon (customer_id, coupon_id, obtain_time, deadline_time)\n" +
            "VALUES (#{customer_id}, #{coupon_id}, NOW(), DATE_ADD(NOW(), INTERVAL #{deadline_time} DAY));")
    Boolean addCouponCustomer(@Param("customer_id") Integer customer_id,
                        @Param("coupon_id") Integer coupon_id,
                        @Param("deadline_time") Long deadline_time);


} 